package testers;

import java.util.Random;
import java.util.Scanner;

import layers.LayerOneClient;
import layers.LayerOneServer;

public class TestersLayerTwo {

	private static String pack;
	private static String characters = "abcdefghijklmnopqrstuvwxyz"; //String of characters where to build the random strings.
	private static Random rng = new Random(); //Object to a new random number generator.
	static int n;
	static String ack;

	public static void main(String[] args) throws Exception {
		
		LayerOneClient clientSocket = new LayerOneClient();
		LayerOneServer serverSocket = new LayerOneServer();
		
		Scanner in = new Scanner(System.in);
		System.out.print("Number of random strings? ");
		n = in.nextInt();
		
		int i = 0;
		Object[] clientData = new Object[3]; 
		while(i++ < n ){
			String temp = generateString(10);
			System.out.println("Sending package: "+i+temp);
			clientSocket.clientSend(i+temp);
			clientData = serverSocket.serverReceived();
			System.out.println("RECEIVED PACKAGE: "+(String)clientData[0]);
		}
		
	}
	
	public static String generateString(int length)
	{
	    char[] text = new char[length];
	    for (int i = 0; i < length; i++)
	    {
	        text[i] = characters.charAt(rng.nextInt(characters.length()));
	    }
	    pack = new String(text);
	    return pack;
	}

}
